<?php
include '../base/validateAdminLogin.php';
include '../class/MMysql.php';

     $property_id = $_GET['property_id'];
     $likes=$_GET['likes'];
     $mysql = new MMysql();
     $property = $mysql
        ->where(array('property_id'=>$property_id))
        ->select('property');
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Property_edit</title>
    <link href="../public/bootstrap/dist/css/bootstrap.css" rel="stylesheet" type="text/css" />
    <link href="../public/xw/css/xcConfirm.css" rel="stylesheet" type="text/css" />

    <link href="../public/umeditor/themes/default/_css/umeditor.css" type="text/css" rel="stylesheet">
    <script src="../public/JQuery.1.11.3.js"></script>
    <script type="text/javascript" charset="utf-8" src="../public/umeditor/umeditor.config.js"></script>

    <script type="text/javascript" charset="utf-8" src="../public/umeditor/_examples/editor_api.js"></script>
    <script type="text/javascript" charset="utf-8" src="../public/umeditor/lang/en/en.js"></script>
    <script src="../public/bootstrap/dist/js/bootstrap.js"></script>
    <script src="../public/xw/js/xcConfirm.js" type="text/javascript" charset="utf-8"></script>

    <!--[if lt IE 9]>
    <script src="http://apps.bdimg.com/libs/html5shiv/3.7/html5shiv.min.js"></script>
    <script src="http://apps.bdimg.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

    <style type="text/css">
        .sgBtn{width: 135px; height: 35px; line-height: 35px; margin-left: 10px; margin-top: 10px; text-align: center; background-color: #0095D9; color: #FFFFFF; float: left; border-radius: 5px;}
        .xcConfirm .popBox .ttBox{
            height:50px;
        }
    </style>

    <style>
        .user_info_input{
            background:none;
            border-top-style: none;
            border-right-style: none;
            border-left-style: none;
            width: 500px;
            height: 34px;
            /*color: rgb(152,152,152);*/
            color: #2B2B2B;;
            outline:none;
            line-height: 34px;
            /*font-size: 20px;*/
            padding: 0px;
            text-align: right;

        }
        .property_span{
            color: rgb(152,152,152);
            font-size: 18px;
            display: block;
            padding-top: 20px;;
        }
        .property_span span{
            font-size: 14px;;
        }
        .user_info_span{
            position: absolute;
            line-height: 34px;
            color: rgb(152,152,152);
        }
        .space10{
            height: 10px;
        }
        .OverlaysBL{
            display:none;
        }
    </style>
</head>
<body onload="getMap()">
<?php
include '../base/header.php';
?>

<section style="width: 100%;">

    <?php
    include '../base/sidemenu.php';
    ?>

    <!-----------------------------------content start------------------------------------->
    <aside class="content">

        <div style="position: relative;margin-top: 60px;margin-left: 40px;">

            <span style="font-size: 40px;">
                Property info
            </span>

            <div style="float: right;">
                    <span style="display: block;color: #9B9B9B;text-align: center;margin-right: 40px;">
                        It got
                        <span style="color:#42A0BD;font-family:.SFNSText-Bold;font-size: 20px;">
                            <?php
                            echo $likes;
                            ?>
                        </span>
                        likes
                    </span>
                
                <?php
                echo '<a href="like_list.php?property_id='.$property[0]['property_id'].'">';
                ?>
                    <button class="btn" style="width: 270px;height: 40px;font-size: 20px; background-color: #42A0BD;color: #D9D9D9;margin-right: 30px;margin-top: 10px;">
                       click to see who like it
                    </button>
                </a>
            </div>

            <br>
            <form role="form">
                <div class="row">
                    <div class="col-md-12">
                        <span class="property_span" >
                            Choose the categories
                        </span>
                        <div class="input-group" style="width: 200px;">
                            <select id="property_category" class="form-control selectpicker" data-mobile="true">
                                <option value="-1">choose</option>;
                                <option value="0">Agribusiness</option>
                                <option value="1">Residential</option>
                                <option value="2">Dream properties</option>
                            </select>
                        </div>
                    </div>
                </div>

                <div class="row">
                    <div class="col-md-12">
                        <span class="property_span">
                            Choose the agent
                        </span>
                        <div class="input-group" style="width: 200px;">
                            <select id="property_agent_id" class="form-control selectpicker" data-mobile="true">
                                <?php
                                $mysql = new MMysql();
                                $res = $mysql
                                    ->select('agent');
                                echo '<option value="-1">choose</option>';
                                for($i=0;$i<count($res);$i++){
                                    echo '<option value="'.$res[$i]['agent_id'].'">'.$res[$i]['agent_name'].'</option>';
                                }
                                ?>
                            </select>
                        </div>
                    </div>
                </div>


                <div class="row">
                    <div class="col-md-12">
                        <span class="property_span">
                            Choose the city
                        </span>
                        <div class="input-group" style="width: 200px;">
                            <select id="property_city_id" class="form-control selectpicker" data-mobile="true">
                                <?php
                                $mysql = new MMysql();
                                $res = $mysql
                                    ->select('city');
                                echo '<option value="-1">choose</option>';
                                for($i=0;$i<count($res);$i++){
                                    echo '<option value="'.$res[$i]['city_id'].'">'.$res[$i]['city_en_name'].'</option>';
                                }
                                ?>
                            </select>
                        </div>
                    </div>
                </div>


                <div class="row">
                    <div class="col-md-12">
                        <span class="property_span">
                            info-1
                        </span>
                        <div>
                             <span class="user_info_span" >
                                 Name of the property
                            </span>
                            <?php
                           echo '<input id="property_name" class="user_info_input" style=" width: 400px;" type="text" value="'.$property[0]['property_name'].'">';
                            ?>

                        </div>

                        <div style="margin-top: 20px;">
                            <span class="user_info_span">
                                Price - Dollar
                            </span>
                            <?php
                            echo '<input id="property_dollar" class="user_info_input" style=" width: 400px;" type="text" value="'.$property[0]['property_dollar'].'"><span style="color: rgb(152,152,152);">&nbsp;$</span>';
                            ?>

                        </div>

                        <div style="margin-top: 20px;">
                            <span class="user_info_span">
                               Price-RMB
                            </span>
                            <?php
                            echo '<input id="property_rmb" class="user_info_input" style=" width: 400px;" type="text" value="'.$property[0]['property_rmb'].'"><span style="color: rgb(152,152,152);">&nbsp;RMB</span>';
                            ?>


                        </div>
                    </div>
                </div>


                <div class="row">
                    <div class="col-md-12">
                        <span class="property_span">
                            Input the important parameters
                            <br>
                            <span>
                                 You can input more than five item
                            </span>

                        </span>
                        <?php
                        echo '<input id="parameter_value1" type="text" class="form-control" style="margin-top: 10px;width: 400px;"
                               placeholder="Area:1866" value="'.$property[0]['parameter_value1'].'">';
                        echo '<input id="parameter_value2" type="text" class="form-control" style="margin-top: 10px;width: 400px;"
                               placeholder="Luxury decoration:a large parking space" value="'.$property[0]['parameter_value2'].'">';
                        echo '<input id="parameter_value3" type="text" class="form-control" style="margin-top: 10px;width: 400px;"
                               placeholder="Third-Click to input" value="'.$property[0]['parameter_value3'].'">';
                        echo '<input id="parameter_value4" type="text" class="form-control" style="margin-top: 10px;width: 400px;"
                               placeholder="Fourth-Click to input" value="'.$property[0]['parameter_value4'].'">';
                        echo '<input id="parameter_value5" type="text" class="form-control" style="margin-top: 10px;width: 400px;"
                               placeholder="Fifth-Click to input" value="'.$property[0]['parameter_value5'].'">';
                        ?>


                    </div>
                </div>

                <div class="row">
                    <div class="col-md-12">
                        <span class="property_span">
                           upload five images
                        </span>
                        <?php
                        echo '<script type="text/plain" id="arr_imgs" style="width:60%;height:240px;">';

                        echo $property[0]['property_imgs'];

                       echo '</script>';

                        ?>
                    </div>
                </div>

                <div class="row">
                    <div class="col-md-12">
                        <span class="property_span">
                            Input the short describ
                        </span>
                        <!--style给定宽度可以影响编辑器的最终宽度-->
                        <script type="text/plain" id="short_describ" style="width:60%;height:240px;">
<?php
                           echo  $property[0]['property_short_desc'];
                            ?>

                         </script>
                    </div>
                </div>

                <div class="row">
                    <div class="col-md-12">
                        <span class="property_span">
                            Input the detail describ
                        </span>
                        <script type="text/plain" id="detail_describ" style="width:60%;height:240px;">
                              <?php
                            echo  $property[0]['property_detail_desc'];
                            ?>
                            </script>
                    </div>
                </div>

                <div style="margin-top: 20px;">
                    <div>
                        <input class="txtsreach form-control" placeholder="input place" type="text"  style="display: inline; margin-top: 10px;width: 200px;" />
                        <input type="button" id="btnsreach" class="btn" value="search" style="background-color: #2B2B2B;color:white;width: 100px;">

                    </div>
                    <div id='myMap' style="position:relative; width:400px; height:400px;margin-top:20px;"></div>
                </div>

                <div style="margin-top: 20px;">
                    <input type="button" id="btnedit" class="btn" value="edit" style="background-color: #2B2B2B;color:white;width: 100px;margin-left: 50px;">

                    <input type="button" id="btndelete" class="btn" value="delete" style="background-color: #2B2B2B;color:white;width: 100px;margin-left: 100px;">
                </div>

            </form>
        </div>
        <div style="height: 100px;position: relative;">

        </div>
    </aside>
    <?php
      echo '<input type="hidden" id="property_id" value="'.$property[0]['property_id'].'" />';
    ?>

    <!-----------------------------------content end------------------------------------->
</section>

</body>
</html>
<script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
    var map = null;
    var searchManager = null;
    function getMap()
    {
        map = new Microsoft.Maps.Map(document.getElementById('myMap'), {
            credentials: 'Aq4dG26RbZekJDIAZCBdNditbr2cinnV1fuSUmkrc8LeRFZpuXlFIzDtYZDQs846'
        });
        updatePushpinLocation();
        function updatePushpinLocation()
        {
            var pushpin= new Microsoft.Maps.Pushpin(map.getCenter(), null);
            map.entities.push(pushpin);
            pushpin.setLocation(new Microsoft.Maps.Location(<?php echo $property[0]['latitude'] ?>, <?php echo $property[0]['longitude'] ?>));
            map.setView({center: new Microsoft.Maps.Location(<?php echo $property[0]['latitude'] ?>, <?php echo $property[0]['longitude'] ?>),zoom: 10 });
        }

    }
    function createSearchManager()
    {
        map.addComponent('searchManager', new Microsoft.Maps.Search.SearchManager(map));
        searchManager = map.getComponent('searchManager');
    }
    function LoadSearchModule()
    {
        Microsoft.Maps.loadModule('Microsoft.Maps.Search', { callback: geocodeRequest })
    }
    function geocodeRequest()
    {
        createSearchManager();
        var where = $(".txtsreach").val();
        var userData = { name: 'Maps Test User', id: 'XYZ' };
        var request =
        {
            where: where,
            count: 5,
            bounds: map.getBounds(),
            callback: onGeocodeSuccess,
            errorCallback: onGeocodeFailed,
            userData: userData
        };
        searchManager.geocode(request);
        getlocation();
    }
    function onGeocodeSuccess(result, userData)
    {
        if (result) {
            map.entities.clear();
            var topResult = result.results && result.results[0];
            if (topResult) {
                var pushpin = new Microsoft.Maps.Pushpin(topResult.location, null);
                map.setView({ center: topResult.location, zoom: 10 });
                map.entities.push(pushpin);
            }
        }
    }
    function onGeocodeFailed(result, userData) {
        alert('Geocode failed');
    }
    function getlocation(){
        var latlon = map.getCenter();
        //console.log('Lat/Long: ' + latlon.latitude +'/' + latlon.longitude)
    }
    $("#btnsreach").click(function () {
        LoadSearchModule();
    })
</script>
<script type="text/javascript">
    <?php
    echo '$("#property_category").val('.$property[0]['property_category'].');';
    echo '$("#property_agent_id").val('.$property[0]['property_agent_id'].');';
    echo '$("#property_city_id").val('.$property[0]['property_city_id'].');';
    ?>

    $(function () {
        var um_detail = UM.getEditor('detail_describ');

        var um_short = UM.getEditor('short_describ');

        $opt={toolbar:[
            'image'
        ]};

        var um_imgs=UM.getEditor('arr_imgs',$opt);
//        alert(um.getContent());

        $(".menu").height($('.content').height());

        //修改
        $("#btnedit").click(function () {
            var property_category= $("#property_category option:selected").val()==-1?"":$("#property_category option:selected").val();
            var property_agent_id= $("#property_agent_id option:selected").val()==-1?"":$("#property_agent_id option:selected").val();
            var property_city_id= $("#property_city_id option:selected").val()==-1?"":$("#property_city_id option:selected").val();
            var property_name=$("#property_name").val();
            var property_dollar=$("#property_dollar").val();
            var property_rmb=$("#property_rmb").val();

            var parameter_value1=$("#parameter_value1").val();
            var parameter_value2=$("#parameter_value2").val();
            var parameter_value3=$("#parameter_value3").val();
            var parameter_value4=$("#parameter_value4").val();
            var parameter_value5=$("#parameter_value5").val();

            var latitude=map.getCenter().latitude;
            var longitude=map.getCenter().longitude;

            var arr= new Array();
            if(parameter_value1!=""){
                arr.push(parameter_value1);
            }
            if(parameter_value2!=""){
                arr.push(parameter_value2);
            }
            if(parameter_value3!=""){
                arr.push(parameter_value3);
            }
            if(parameter_value4!=""){
                arr.push(parameter_value4);
            }
            if(parameter_value5!=""){
                arr.push(parameter_value5);
            }
            var parameter_value=JSON.stringify(arr);

            var property_imgs=um_imgs.getContent();
            var property_short_desc=um_short.getContent();
            var property_detail_desc=um_detail.getContent();

            if(property_category==""){
                alert("property category is not null");
                return;
            }

            if(property_agent_id==""){
                alert("agent is not null");
                return;
            }

            if(property_city_id==""){
                alert("city is not null");
                return;
            }

            if(property_name==""){
                alert("name not null");
                return;
            }
            if(property_dollar==""){
                alert("dollar not null");
                return;
            }
            if(property_rmb==""){
                alert("RMB not null");
                return;
            }
//            console.log('property_category',property_category);
//            console.log('property_detail_desc',property_detail_desc);
            $.ajax( {
                url: '../class/property/propertyfuction.php',
                data:{
                    method:'update',
                    property_category : property_category,
                    property_agent_id : property_agent_id,
                    property_city_id : property_city_id,
                    property_name : property_name,
                    property_dollar : property_dollar,
                    property_rmb : property_rmb,
//                         parameter_value : parameter_value,
                    parameter_value1 : parameter_value1,
                    parameter_value2 : parameter_value2,
                    parameter_value3 : parameter_value3,
                    parameter_value4 : parameter_value4,
                    parameter_value5 : parameter_value5,
                    property_imgs : property_imgs,
                    property_short_desc : property_short_desc,
                    property_detail_desc : property_detail_desc,
                    property_id:$("#property_id").val(),
                    latitude:latitude,
                    longitude:longitude
                },
                type:'post',
                success:function(data) {
//                    alert(data);
                    if(data==1){
                        window.wxc.xcConfirm('edit success', window.wxc.xcConfirm.typeEnum.success);
                    }
                },
                beforeSend: function(){
                    //$('#warning').text('正在处理，请稍等！');
                },
                error : function() {
                    // view("异常！");
                    window.wxc.xcConfirm('edit success', window.wxc.xcConfirm.typeEnum.error);
                }
            });

        });

        //删除
        $("#btndelete").click(function () {

            var txt=  "sure delete?";
            window.wxc.xcConfirm(txt, window.wxc.xcConfirm.typeEnum.confirm,{
                onOk:function(v){
                    $.ajax( {
                        url: '../class/property/propertyfuction.php',
                        data:{
                            method:'delete',
                            property_id:$("#property_id").val()
                        },
                        type:'get',

                        success:function(data) {

                            if(data==1){
                                alert('delete success');
                                window.location.href='property_list.php';
                            }
                        },
                        beforeSend: function(){
                            //$('#warning').text('正在处理，请稍等！');
                        },
                        error : function() {

                            alert("fail");
                        }
                    });
                }
            });



            });

    });

</script>


